<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="websocket.js"></script>
</head>
<body>
    <input type="text" placeholder="insert your content" id="text"/>
    <input type="text" placeholder="目标id" id="ObjId"/>
    <button onclick="clickButton()">发送</button>
    <div id="content"></div>

<script>
    var input = document.getElementById('text')
    var button = document.querySelector('button')
    var div = document.getElementById('content')

    var websocket = new WebSocket("ws://127.0.0.1:8090/Websocket/"+447);

    websocket.addEventListener('open', function (){
        div.innerHTML = '连接成功'
    })

    websocket.addEventListener('message', function (e) {
        console.log(e.data)
        var dv = document.createElement('div')
        dv.innerText = e.data
        div.appendChild(dv)
    })

    websocket.addEventListener('close', function (){
        console.log("连接断开")
    })

    function clickButton(){
        var value = document.getElementById("text").value;
        websocket.send(value+"`"+document.getElementById("ObjId").value);
        input.value = ''
    }
</script>
</body>
</html>